import type { IConstantInterface } from '@/types/constant-interface'

export default class ConstantBase {
  /**
   * 导出全部常量
   */
  public list() {
    const props = Object.getOwnPropertyDescriptors(this);
    const attrs: IConstantInterface[] = [];
    for (const key in props) {
      if (Object.prototype.hasOwnProperty.call(props, key)) {
        const element = props[key];
        attrs.push(element.value);
      }
    }
    return attrs;
  }

  /**
   * value转到label
   */
  public toLabel(value: number | string) {
    const list = this.list();
    const find = list.find(x => x.value == value);
    return find?.label || "";
  }
}